﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Incapacities", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(Incapacities))]
    public class IncapacitiesSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IIncapacities clazz;
        
        public IncapacitiesSerializer(IIncapacities clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (((clazz.Incapacities0 == null) 
                        || (clazz.Incapacities0.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "Incapacities");
            }
            for (int x = 0; ((clazz.Incapacities0 != null) 
                        && (x < clazz.Incapacities0.Count)); x = (x + 1)) {
                Writer.WriteStartElement("Incapacities");
                if (clazz.Incapacities0[x]!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Incapacities0[x]))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Incapacities0");
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            clazz.Incapacities0 = new System.Collections.Generic.List<System.String>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "Incapacities")); ) {
                if (Reader.LocalName=="Incapacities") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Incapacities>Incapacities");
                    }
                    clazz.Incapacities0.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Incapacities")).Value);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Incapacities>Incapacities", Reader.LocalName);
                }
            }
            if ((clazz.Incapacities0.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "Incapacities");
            }
        }
    }
}
